cmake_minimum_required(VERSION 3.15)

project(
  "bdpp"
  VERSION "0.0.1"
  DESCRIPTION "build tool testing"
  LANGUAGES CXX)
message(STATUS "${CMAKE_PROJECT_DESCRIPTION} version: ${CMAKE_PROJECT_VERSION}")

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX
      ${CMAKE_SOURCE_DIR}/.build-tool/install
      CACHE PATH "Set installation location" FORCE)
endif()
message(STATUS "Set installation location: ${CMAKE_INSTALL_PREFIX}")

if(NOT CMAKE_PREFIX_PATH)
  set(CMAKE_PREFIX_PATH
      ${CMAKE_INSTALL_PREFIX}
      CACHE PATH "Set library location" FORCE)
endif()
message(STATUS "Set library location: ${CMAKE_PREFIX_PATH}")

set(DEFAULT_BUILD_TYPE "Debug")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE
      ${DEFAULT_BUILD_TYPE}
      CACHE STRING "Set build type" FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
                                               "RelWithDebInfo" "MinSizeRel")
endif()
message(STATUS "Set cmake build type: ${CMAKE_BUILD_TYPE}")

set(DEFAULT_CXX_STANDARD 20)
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD
      ${DEFAULT_CXX_STANDARD}
      CACHE STRING "Set CXX standard" FORCE)
  set_property(CACHE CMAKE_CXX_STANDARD PROPERTY STRINGS "11" "14" "17" "20"
                                                 "23")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Set cmake CXX standard: c++${CMAKE_CXX_STANDARD}")

include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake)

# Add dependency.

list(APPEND DEPENDENCE unwind)
find_package(benchmark CONFIG REQUIRED)
list(APPEND DEPENDENCE benchmark::benchmark)
find_package(GTest CONFIG REQUIRED)
list(APPEND DEPENDENCE GTest::gtest GTest::gmock)
find_package(fmt CONFIG REQUIRED)
list(APPEND DEPENDENCE fmt::fmt)
find_package(quill CONFIG REQUIRED)
list(APPEND DEPENDENCE quill::quill)
find_package(CURL CONFIG REQUIRED)
list(APPEND DEPENDENCE CURL::libcurl)
find_package(absl CONFIG REQUIRED)
list(
  APPEND
  DEPENDENCE
  absl::algorithm
  absl::base
  absl::debugging
  absl::flat_hash_map
  absl::flags
  absl::log
  absl::log_initialize
  absl::memory
  absl::meta
  absl::numeric
  absl::random_random
  absl::strings
  absl::synchronization
  absl::time
  absl::utility)

message(STATUS "Dependency libraries: ${DEPENDENCE}")

# Add global target.

add_library(parser)
add_library(bdpp::parser ALIAS parser)
target_sources(parser PRIVATE src/parser.cc)
target_include_directories(parser PRIVATE $<INSTALL_INTERFACE:include>)
set_common_compile_options(parser)
# find_package(bdpp CONFIG REQUIRED COMPONENTS parser)

add_subdirectory(bench)
enable_testing()
add_subdirectory(test)

add_executable(main)
target_sources(main PRIVATE src/main.cc)
set_common_compile_options(main bdpp::parser)

add_executable(log)
target_sources(log PRIVATE src/log.cc)
set_common_compile_options(log)

project_install(parser)
